package com.lheia.downloader.phantomjs

import org.openqa.selenium.phantomjs.PhantomJSDriver
import org.openqa.selenium.phantomjs.PhantomJSDriverService
import org.openqa.selenium.remote.DesiredCapabilities

class PhantomJSDriverFactory{
     static PhantomJSDriver create(String phantomjsBinaryPath){
        //设置必要参数
         DesiredCapabilities dcaps = new DesiredCapabilities()
        //ssl证书支持
        dcaps.setCapability("acceptSslCerts", true)
        //截屏支持
        dcaps.setCapability("takesScreenshot", false)
        //css搜索支持
        dcaps.setCapability("cssSelectorsEnabled", true)
        //js支持
        dcaps.setJavascriptEnabled(true)
        //驱动支持
        dcaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,phantomjsBinaryPath)

        PhantomJSDriver driver = new PhantomJSDriver(dcaps);
        return  driver;
    }
}
